package com.manong.bookstore.order.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.manong.bookstore.order.entity.OrderEntity;
import com.manong.bookstore.order.service.OrderService;
import com.manong.common.utils.PageUtils;
import com.manong.common.utils.R;



/**
 * 
 *
 * @author cyq
 * @email 465447222@qq.com
 * @date 2021-01-26  21:37:15
 */
@RestController
@RequestMapping("order/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 查询所有订单
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = orderService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 店铺查询所有订单
     */
    @RequestMapping("/listStore/{storeId}")
    public R listByStoreId(@RequestParam Map<String, Object> params,@PathVariable("storeId") Long storeId){
        PageUtils page = orderService.queryPage(params,storeId);

        return R.ok().put("page", page);
    }

    /**
     * 用户查询所有订单
     */
    @RequestMapping("/listUser/{userId}")
    public R listByUserId(@RequestParam Map<String, Object> params,@PathVariable("userId") Long userId){
        PageUtils page = orderService.queryPage2(params,userId);

        return R.ok().put("page", page);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{orderId}")
    public R info(@PathVariable("orderId") Integer orderId){
		OrderEntity order = orderService.getById(orderId);

        return R.ok().put("order", order);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody OrderEntity order){
		orderService.save(order);

        return R.ok().put("order",order);
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody OrderEntity order){
		orderService.updateById(order);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] orderIds){
		orderService.removeByIds(Arrays.asList(orderIds));

        return R.ok();
    }

    @RequestMapping("/getByPayStatus")
    public R getByPayStatus(){
        OrderEntity order ;

        return R.ok();
    }

}
